import common from '@/assets/js/common'
import lodash from 'lodash'
import { LEVEL_ID, LEVEL_INT, INT_LEVEL, GRADE_NAME } from './area'

const DEFAULT_ATTEND = {
  id: null,
  name: null,
  warnCount: 0,
  jcCount: 0,
  fyCount: 0,
  gcCount: 0,
  attendCount: 0,
  totalCount: 0,
  leaveCount: 0
}

const DEFAULT_SPORT_SLEEP = {
  id: null,
  name: null,
  averageHeavy: 0,
  averageCenter: 0,
  averageLower: 0,
  percentHeavy: 0,
  percentCenter: 0,
  percentLowery: 0,
  averageSleep: 0,
  averageNoSleep: 0,
  averageLessSleep: 0,
  averageNormalSleep: 0,
  averageMoreSleep: 0,
  percentNoSleep: 0,
  percentLessSleep: 0,
  percentNormalSleep: 0,
  percentMoreSleep: 0
}

const DEFAULT_CHECK = {
  '偏轻': 0,
  '正常': 0,
  '偏胖': 0,
  '肥胖': 0
}
const DEFAULT_CHECK_LIST = ['偏轻', '正常', '偏胖', '肥胖']
const DEFAULT_AVG_CHECK = {
  id: null,
  name: null,
  gender: {
    0: 0,
    1: 0
  }
}

const addLevel = (level, val) => INT_LEVEL[(LEVEL_INT[level] + val).toString()]
const fixAttend = (item) => common.copy(item, DEFAULT_ATTEND)
const fixSportSleep = (item) => common.copy(item, DEFAULT_SPORT_SLEEP)
const fixAvgCheck = (item) => common.copy(item, DEFAULT_AVG_CHECK)

const getKVPair = list => list ? list.map(i => ({
  name: i.item1,
  value: i.item2
})) : [{
  name: '暂无数据',
  value: 0
}]

const getters = {
  isLogin: state => !!state.user,
  attendWarnPercent: state => (state.warnPercent.attend * 100).toString(),
  sickWarnPercent: state => (state.warnPercent.sick * 100).toString(),
  areaFetched: state => !!state.areaIdList,
  gardenFetched: state => !!state.gardenIdList,
  cityMapFetched: state => !!state.cityMap,
  provincesFetched: state => !!state.provinces,
  userLevel: state => state.user ? state.user.level : '区级',
  userLevelInt: (_, getters) => LEVEL_INT[getters.userLevel],
  area: state => state.mapArea ? state.mapArea.name : null,
  areaLevel: state => state.mapArea ? state.mapArea.level : '省级',
  areaLevelInt: (_, getters) => LEVEL_INT[getters.areaLevel],
  subAreaLevel: (_, getters) => addLevel(getters.areaLevel, 1),
  isGardenLevel: (_, getters) => getters.areaLevel === '园级',
  mapAreaObj: (state) => state.mapArea || {},
  generalOverviewObj: (_, getters) => getters.mapAreaObj.generalOverview || {},
  sleepOverview: (_, getters) => getKVPair(getters.mapAreaObj.sleepOverview ? getters.mapAreaObj.sleepOverview.sleep : null),
  sportOverview: (_, getters) => getKVPair(getters.mapAreaObj.sleepOverview ? getters.mapAreaObj.sleepOverview.sport : null),
  sportAndSleep: (_, getters) => (getters.mapAreaObj.sportAndSleep ? getters.mapAreaObj.sportAndSleep : []).map(item => fixSportSleep(item)),
  attend: (_, getters) => (getters.mapAreaObj.attend ? getters.mapAreaObj.attend : []).map(item => fixAttend(item)),
  allCheck: (_, getters) => {
    if (!getters.mapAreaObj.check) return []
    const { areas, mapAreaObj: { check } } = getters
    return areas.map(a => {
      const checks = check.filter(i => i.id === a.id)
      return {
        ...a,
        ...DEFAULT_CHECK,
        ...lodash.countBy(checks, 'BMIResult')
      }
    })
  },
  genderCheck: (_, getters) => {
    if (!getters.mapAreaObj.check) return {}
    const { mapAreaObj: { check } } = getters
    return lodash.map(lodash.groupBy(check, 'Gender'), list => {
      const counter = lodash.countBy(list, 'BMIResult')
      return [...DEFAULT_CHECK_LIST].map(name => ({
        name,
        value: counter[name] ? counter[name] : 0
      }))
    })
  },
  // 各年级男童/女童BMI分布-女童
  girlCheck: (_, getters) => {
    // 增加对genderCheck的绑定
    const { genderCheck } = getters
    return {
      color: ['#ff6c6c', '#ff9786', '#ffd05a', '#ffe98f', '#9d70ff'],
      title: '女童',
      data: genderCheck['0'] || [{name: '暂无数据', value: 0}]
    }
  },
  // 各年级男童/女童BMI分布-男童
  boyCheck: (_, getters) => {
    const { genderCheck } = getters
    return {
      color: ['#315bff', '#7193ff', '#53e9ee', '#a4ffee', '#24cbff'],
      title: '男童',
      data: genderCheck['1'] || [{name: '暂无数据', value: 0}]
    }
  },
  avgCheck: (_, getters) => {
    if (!getters.mapAreaObj.avgCheck) return {}
    const { mapAreaObj: { avgCheck } } = getters
    return ['AvgHeight', 'AvgWeight'].reduce((res, k) => {
      res[k] = lodash.map(lodash.groupBy(avgCheck, 'AreaId'), v => ({
        id: v[0].AreaId,
        name: v[0].AreaName,
        gender: {
          '0': 0,
          '1': 0,
          ...lodash.map(lodash.groupBy(v, 'Gender'), c => Math.round(lodash.sumBy(c, k) / c.length))
        }
      }))
      return res
    }, {})
  },
  allAvgHeight: (_, getters) => {
    const { areas, avgCheck } = getters
    if (!avgCheck.AvgHeight) return []
    const { AvgHeight: avgHeight } = avgCheck
    return areas.map(a => avgHeight.filter(i => i.id === a.id)[0] || fixAvgCheck(a))
  },
  // 以平均身高高低排名
  avgHeightRank: (_, getters) => {
    const opt = {
      xData: ['暂无数据'],
      data: [{
        name: '男童',
        value: [0]
      }, {
        name: '女童',
        value: [0]
      }],
      color: ['#53e9ee', '#ffe98f'],
      yName: '身高（cm）'
    }
    const { allAvgHeight } = getters
    if (allAvgHeight.length > 0) {
      const ordered = lodash.orderBy(allAvgHeight, i => i.gender['0'] + i.gender['1'], 'desc')
      opt.xData = ordered.map(i => i.name)
      opt.data[0].value = ordered.map(i => i.gender['1'])
      opt.data[1].value = ordered.map(i => i.gender['0'])
    }
    return opt
  },
  allAvgWeight: (_, getters) => {
    const { areas, avgCheck } = getters
    if (!avgCheck.AvgWeight) return []
    const { AvgWeight: avgWeight } = avgCheck
    return areas.map(a => avgWeight.filter(i => i.id === a.id)[0] || fixAvgCheck(a))
  },
  // 以平均身高高低排名
  avgWeightRank: (_, getters) => {
    const opt = {
      xData: ['暂无数据'],
      data: [{
        name: '男童',
        value: [0]
      }, {
        name: '女童',
        value: [0]
      }],
      yName: '体重（kg）',
      color: ['#ff6dff', '#315bff'],
      grid: {
        top: '20%',
        left: '0%',
        right: '0%',
        bottom: '10%',
        containLabel: true
      }
    }
    const { allAvgWeight } = getters
    if (allAvgWeight.length > 0) {
      const ordered = lodash.orderBy(allAvgWeight, i => i.gender['0'] + i.gender['1'], 'desc')
      opt.xData = ordered.map(i => i.name)
      opt.data[0].value = ordered.map(i => i.gender['1'])
      opt.data[1].value = ordered.map(i => i.gender['0'])
    }
    return opt
  },
  avgGardenCheck: (_, getters) => {
    if (!getters.mapAreaObj.avgGardenCheck) return {}
    const { mapAreaObj: { avgGardenCheck } } = getters
    return ['ClassAvgHeight', 'ClassAvgWeight'].reduce((res, k) => {
      res[k] = avgGardenCheck.map(g => {
        const gradeData = lodash.flatten(g.classdatas.map(c => c.datas))
        return {
          id: g.GradeId,
          name: g.GradeName,
          gender: {
            '0': 0,
            '1': 0,
            ...lodash.map(lodash.groupBy(gradeData, 'sex'), gc => Math.round(lodash.sumBy(gc, k) / gc.length))
          }
        }
      })
      return res
    }, {})
  },
  avgGardenHeightRank: (_, getters) => {
    const opt = {
      xData: ['暂无数据'],
      data: [{
        name: '男童',
        value: [0]
      }, {
        name: '女童',
        value: [0]
      }],
      color: ['#53e9ee', '#ffe98f'],
      yName: '身高（cm）'
    }
    let { avgGardenCheck } = getters
    if (avgGardenCheck.ClassAvgHeight) {
      let { ClassAvgHeight: allAvgHeight } = avgGardenCheck
      allAvgHeight = allAvgHeight.filter(c => c.gender['0'] && c.gender['1'])
      if (allAvgHeight.length > 0) {
        const ordered = lodash.orderBy(allAvgHeight, i => i.gender['0'] + i.gender['1'], 'desc')
        opt.xData = ordered.map(i => i.name)
        opt.data[0].value = ordered.map(i => i.gender['1'])
        opt.data[1].value = ordered.map(i => i.gender['0'])
      }
    }
    return opt
  },
  avgGardenWeightRank: (_, getters) => {
    const opt = {
      xData: ['暂无数据'],
      data: [{
        name: '男童',
        value: [0]
      }, {
        name: '女童',
        value: [0]
      }],
      yName: '体重（kg）',
      color: ['#53e9ee', '#ffe98f']
    }
    let { avgGardenCheck } = getters
    if (avgGardenCheck.ClassAvgWeight) {
      let { ClassAvgWeight: allAvgWeight } = avgGardenCheck
      allAvgWeight = allAvgWeight.filter(c => c.gender['0'] && c.gender['1'])
      if (allAvgWeight.length > 0) {
        const ordered = lodash.orderBy(allAvgWeight, i => i.gender['0'] + i.gender['1'], 'desc')
        opt.xData = ordered.map(i => i.name)
        opt.data[0].value = ordered.map(i => i.gender['1'])
        opt.data[1].value = ordered.map(i => i.gender['0'])
      }
    }
    return opt
  },
  warnAttend: (state, getters) => {
    const { attend, sick } = state.warnPercent
    return getters.attend.filter(a => a.leaveCount / a.totalCount >= attend || a.warnTempCount / a.totalCount >= sick)
  },
  allAttend: (_, getters) => {
    let list = getters.attend
    return getters.areas.map(a => list.filter(i => common.featureMatch(a, i))[0] || fixAttend(a))
  },
  // 以出勤记录情况排名
  allAttendDetail (_, getters) {
    const attends = {
      xData: ['暂无数据'],
      data: [0],
      linearGradient: ['#53e9ee', '#325fff'],
      hasLine: true,
      yName: '人数（人）',
      grid: {
        top: '20%',
        left: '0%',
        right: '0%',
        bottom: '0%',
        containLabel: true
      }
    }
    const { allAttend } = getters
    if (allAttend.length > 0) {
      const ordered = lodash.orderBy(allAttend, 'attendCount', 'desc')
      attends.xData = ordered.map(a => a.name)
      attends.data = ordered.map(a => a.attendCount)
    }
    return attends
  },
  gradeAttendDetail (_, getters) {
    const opt = {
      xData: ['暂无数据'],
      maxVal: 10,
      data: ['0'],
      linearGradient: ['#53e9ee', '#325fff'],
      hasLine: true,
      labelHide: true,
      labelNuit: '{c}%',
      yName: '百分比(%)',
      grid: {
        top: '20%',
        left: '0%',
        right: '0%',
        bottom: '0%',
        containLabel: true
      }
    }
    let { attend } = getters
    attend = attend.filter(a => a.gradeNum > 0 && a.gradeNum < 5 && a.attendCount !== 0)
    if (attend.length > 0) {
      attend = attend.map(a => ({
        ...a,
        name: GRADE_NAME[a.gradeNum.toString()],
        rate: (a.attendCount / a.totalCount * 100).toFixed(2)
      }))
      attend = lodash.orderBy(attend, 'rate', 'desc')
      opt.xData = attend.map(a => a.name)
      opt.data = attend.map(a => a.rate)
      opt.maxVal = attend[0].rate
    }
    return opt
  },
  // 以体温报警人数排名
  allTempDetail (_, getters) {
    const temps = {
      xData: ['暂无数据'],
      data: [0],
      linearGradient: ['#ff9786', '#ffe98f'],
      hasLine: true,
      yName: '人数（人）',
      grid: {
        top: '20%',
        left: '0%',
        right: '0%',
        bottom: '10%',
        containLabel: true
      }
    }
    const { allAttend } = getters
    if (allAttend.length > 0) {
      const ordered = lodash.orderBy(allAttend, 'warnCount', 'desc')
      temps.xData = ordered.map(a => a.name)
      temps.data = ordered.map(a => a.warnCount)
    }
    return temps
  },
  gradeTempDetail (_, getters) {
    const opt = {
      xData: ['暂无数据'],
      data: ['0'],
      maxVal: 20,
      linearGradient: ['#ff9786', '#ffe98f'],
      labelHide: true,
      hasLine: true,
      yName: '人数（人）',
      grid: {
        top: '20%',
        left: '0%',
        right: '0%',
        bottom: '0%',
        containLabel: true
      }
    }
    let { attend } = getters
    attend = attend.filter(a => a.gradeNum > 0 && a.gradeNum < 5 && a.warnCount !== 0)
    if (attend.length > 0) {
      attend = lodash.orderBy(attend, 'warnCount', 'desc')
      opt.xData = attend.map(a => GRADE_NAME[a.gradeNum.toString()])
      opt.data = attend.map(a => a.warnCount)
      opt.maxVal = attend[0].warnCount
    }
    return opt
  },
  allSportAndSleep: (_, getters) => {
    const {
      sportAndSleep,
      areas
    } = getters
    return areas.map(a => sportAndSleep.filter(i => common.featureMatch(a, i))[0] || fixSportSleep(a))
  },
  tagInfo: (state, getters) => {
    switch (state.mapTag) {
      case '睡眠/体育活动':
        return getters.allSportAndSleep
      case '健康安全':
        return getters.allAttend
      case '身体发育':
        return getters.allCheck
      default:
        return []
    }
  },
  // 以平均睡眠时长排名
  averageSleep: (_, getters) => {
    let src = common.sortBy(getters.allSportAndSleep, 'averageSleep').slice().reverse()
    return {
      xData: src.map(i => i.name),
      data: [{
        value: src.map(i => i.averageSleep)
      }],
      color: ['#53e9ee'],
      yName: '时长（分）'
    }
  },
  // 平均运动强度
  averageExercise: (_, getters) => {
    let src = common.sortBy(getters.allSportAndSleep, 'averageHeavy').slice().reverse()
    return {
      xData: src.map(i => i.name),
      data: [{
        name: '高强度',
        value: src.map(i => i.averageHeavy)
      }, {
        name: '中强度',
        value: src.map(i => i.averageCenter)
      }, {
        name: '低强度',
        value: src.map(i => i.averageLower)
      }],
      yName: '时长（分）'
    }
  },
  gradeAverageSleep: state => {
    const opt = {
      xData: ['暂无数据'],
      data: ['0'],
      maxVal: 0,
      linearGradient: ['#ff9786', '#ffe98f'],
      hasLine: false,
      yName: '时间（分）',
      grid: {
        top: '20%',
        left: '0%',
        right: '0%',
        bottom: '0%',
        containLabel: true
      }
    }
    let { gradeSportAndSleep } = state
    if (gradeSportAndSleep && gradeSportAndSleep.gardenSleep) {
      let sleep = gradeSportAndSleep.gardenSleep.filter(s => s.gradeNum > 0 && s.gradeNum < 5 && s.averageSleepTime !== 0)
      if (sleep.length > 0) {
        sleep = lodash.orderBy(sleep, 'averageSleepTime', 'desc')
        opt.xData = sleep.map(s => GRADE_NAME[s.gradeNum.toString()])
        opt.data = sleep.map(s => s.averageSleepTime * 60)
        opt.maxVal = lodash.map(opt.data) + 20
      }
    }
    return opt
  },
  gradeAverageExercise: state => {
    const opt = {
      xData: ['暂无数据'],
      data: ['0'],
      maxVal: 0,
      linearGradient: ['#ff9786', '#ffe98f'],
      hasLine: false,
      yName: '动量',
      grid: {
        top: '20%',
        left: '0%',
        right: '0%',
        bottom: '0%',
        containLabel: true
      }
    }
    let { gradeSportAndSleep } = state
    if (gradeSportAndSleep && gradeSportAndSleep.gardenSport) {
      let sport = gradeSportAndSleep.gardenSport.filter(s => s.gradeNum > 0 && s.gradeNum < 5 && s.averageSport !== 0)
      if (sport.length > 0) {
        sport = lodash.orderBy(sport, 'averageSport', 'desc')
        opt.xData = sport.map(s => GRADE_NAME[s.gradeNum.toString()])
        opt.data = sport.map(s => s.averageSport)
        opt.maxVal = lodash.map(opt.data) + 20
      }
    }
    return opt
  },
  // 睡眠情况分布
  // {value: 0, name: '基本没睡'},
  // {value: 0, name: '睡眠较少'},
  // {value: 0, name: '睡眠正常'},
  // {value: 0, name: '睡眠充足'}
  sleepQuality: (_, getters) => ({
    data: getters.sleepOverview,
    color: ['#00bbf4', '#2dcfea', '#cdffc2', '#2dcfea'],
    title: '睡眠'
  }),
  gardenSleepQuality: (_, getters) => ({
    ...getters.sleepQuality,
    pieSize: {
      radius: '55%',
      center: ['50%', '42%'],
      title: {
        top: 62,
        fontSize: 18
      }
    }
  }),
  // 运动情况分布
  // {value: 0, name: '运动强度高'},
  // {value: 0, name: '运动强度中'},
  // {value: 0, name: '运动强度低'}
  sportQuality: (_, getters) => ({
    data: getters.sportOverview,
    color: ['#315bff', '#64dbff', '#ff6dff'],
    title: '运动'
  }),
  gardenSportQuality: (_, getters) => ({
    ...getters.sportQuality,
    color: ['#00bbf4', '#2dcfea', '#cdffc2', '#2dcfea'],
    pieSize: {
      radius: '55%',
      center: ['50%', '42%'],
      title: {
        top: 62,
        fontSize: 18
      }
    }
  }),
  // 幼儿园信息
  gardenOverview: (_, getters) => [{
    unit: '家',
    subText: '园所总数',
    sum: getters.generalOverviewObj.gardenCount || 0
  },
  {
    unit: '人',
    subText: '园长总数',
    sum: getters.generalOverviewObj.kindergartenCount || 0
  },
  {
    unit: '人',
    subText: '在职教师总数',
    sum: getters.generalOverviewObj.teacherCount || 0
  },
  {
    unit: '人',
    subText: '在园儿童总数',
    sum: getters.generalOverviewObj.totalCount || 0
  }],
  // 年龄分布
  ageData: (_, getters) => ({
    color: ['#1683fb', '#61ffe1', '#24cbff', '#7189ff'],
    title: '年龄分布',
    pieSize: {
      radius: ['35%', '45%'],
      center: ['50%', '35%'],
      title: {
        top: 52,
        fontSize: 12
      }
    },
    data: (getters.generalOverviewObj.ages && getters.generalOverviewObj.ages.length > 0) ? ['00', '90', '80', '70'].map(a => {
      let age = getters.generalOverviewObj.ages.map(ai => ({
        item1: parseInt(ai.item1) < 70 ? '00' : `${Math.floor(parseInt(ai.item1) / 10)}0`,
        item2: ai.item2
      })).filter(ai => ai.item1 === a)[0]
      return {
        name: `${a}后`,
        value: age ? age.item2 : 0
      }
    }) : [{
      name: '暂无数据',
      value: 0
    }]
  }),
  // 职称分布
  jobData: (_, getters) => ({
    color: ['#ffbc00', '#57d0ff', '#4d6bff', '#ff6562', '#9d70ff'],
    title: '职称分布',
    pieSize: {
      radius: ['35%', '45%'],
      center: ['50%', '35%'],
      title: {
        top: 52,
        fontSize: 12
      }
    },
    data: (getters.generalOverviewObj.jobs && getters.generalOverviewObj.jobs.length > 0) ? ['正高级', '高级', '一级', '二级', '三级'].map(l => {
      let job = getters.generalOverviewObj.jobs.filter(j => j.item1 === l)[0]
      return {
        name: l,
        value: job ? job.item2 : 0
      }
    }) : [{
      name: '暂无数据',
      value: 0
    }]
  }),
  crumbs: state => state.crumbs ? {
    province: state.crumbs[0].name,
    city: state.crumbs[1] ? state.crumbs[1].name : null,
    district: state.crumbs[2] ? state.crumbs[2].name : null,
    garden: state.crumbs[3] ? state.crumbs[3].name : null
  } : {},
  crumbIds: state => ({
    province: null,
    city: null,
    district: null,
    garden: null,
    ...(state.crumbs ? {
      province: state.crumbs[0].id,
      city: state.crumbs[1] ? state.crumbs[1].id : null,
      district: state.crumbs[2] ? state.crumbs[2].id : null,
      garden: state.crumbs[3] ? state.crumbs[3].id : null
    } : {})
  }),
  backable: (_, getters) => getters.areaLevelInt > getters.userLevelInt,
  areas (state, getters) {
    if (!state.mapArea) return []
    switch (state.mapArea.level) {
      case '省级':
        if (!state.areaIdList) return []
        return getters.areaTree.city.map(c => ({
          id: c.id,
          name: c.name
        }))
      case '市级':
        if (!state.areaIdList) return []
        const city = getters.areaTree.city.filter(c => c.id === state.mapArea.id)[0]
        return city ? city.district : []
      case '区级':
      case '园级':
        return getters.gardenFeatures || []
    }
  },
  areaTree (state) {
    if (!state.areaIdList || !state.user) return {}
    return {
      name: state.user.province,
      city: Object.values(common.groupBy(state.areaIdList, 'CityName')).map(l => ({
        id: l[0].CityId,
        name: l[0].CityName,
        district: l.map(d => ({
          id: d.DistrictId,
          name: d.DistrictName
        }))
      }))
    }
  },
  areaKey: (state, getters) => getters.areaLevelInt > 3 ? state.mapArea.id : getters.area,
  featureNames (state, getters) {
    if (!getters.mapAreaObj.features) return []
    return state.mapArea.features.features.map(f => f.properties.name)
  },
  featurePairs (state, getters) {
    if (!getters.mapAreaObj.features) return []
    return state.mapArea.features.features.map(f => ({
      name: f.properties.name,
      value: f.centerPoint
    }))
  },
  areaMapList (state, getters) {
    if (!state.mapArea) return []
    if (getters.areaLevelInt < 3) return getters.featureNames
    const list = getters.gardenFeatures ? getters.gardenFeatures.map(g => g.name) : []
    return list.length === 0 ? ['暂无'] : list
  },
  attendWarnFeatures: (_, getters) => {
    let areaMapList = getters.areaMapList
    let warnAttend = getters.warnAttend
    return areaMapList.filter(a => a.id === undefined ? warnAttend.some(w => w.name === a) : warnAttend.some(w => w.id === a.id))
  },
  gardenFeatures: (state) => {
    if (!state.gardenIdList || !state.mapArea) return []
    return state.gardenIdList.filter(g => g[LEVEL_ID[state.mapArea.level]] === state.mapArea.id).map(g => ({
      id: g.gardenId,
      name: g.gardenName,
      value: [g.longitude, g.latitude]
    }))
  },
  attendWarnTip: (state, getters) => {
    const warn = {
      attend: {
        show: false,
        value: 0
      },
      sick: {
        show: false,
        value: 0
      }
    }
    if (getters.mapAreaObj.attendOverview) {
      const { leaveCount, totalCount, gcCount, fyCount } = state.mapArea.attendOverview
      const { attend, sick } = state.warnPercent

      warn.attend.show = leaveCount / totalCount >= attend
      warn.attend.value = ((leaveCount / totalCount - attend) * 100).toFixed(2)
      warn.sick.show = (gcCount + fyCount) / totalCount >= sick
      warn.sick.value = (((gcCount + fyCount) / totalCount - sick) * 100).toFixed(2)
    }
    return warn
  },
  // 今日出勤统计
  attendOverviewDetail: (_, getters) => {
    const { attendCount, leaveCount, totalCount } = getters.mapAreaObj.attendOverview || {}
    return [{
      unit: '人',
      subText: '已出勤人数',
      sum: attendCount || 0
    },
    {
      unit: '人',
      subText: '请假人数',
      sum: leaveCount || 0
    },
    {
      unit: '人',
      subText: '预估缺勤人数',
      sum: (totalCount - attendCount) || 0
    }]
  },
  // 今日晨检统计
  tempOverviewDetail: (_, getters) => {
    const { normalTempCount, warnTempCount } = getters.mapAreaObj.attendOverview || {}
    return {
      xData: ['体温正常', '体温偏高'],
      data: [normalTempCount || 0, warnTempCount || 0],
      linearGradient: ['#ffe98f', '#2dffff'],
      maxVal: 70,
      yHide: true,
      labelHide: true,
      grid: {
        top: '5%',
        left: '0%',
        right: '0%',
        bottom: '0%',
        containLabel: true
      }
    }
  },
  snackOverviewDetail: (_, getters) => {
    const { jcCount, fyCount, gcCount } = getters.mapAreaObj.attendOverview || {}
    return {
      xData: ['需要加餐', '需要服药', '需要观察'],
      data: [jcCount || 0, fyCount || 0, gcCount || 0],
      linearGradient: ['#2de7ff', '#ff6dff'],
      maxVal: 70,
      yHide: true,
      labelHide: true,
      grid: {
        top: '5%',
        left: '0%',
        right: '0%',
        bottom: '0%',
        containLabel: true
      }
    }
  }
}

export default getters
